home *** CD-ROM | disk | FTP | other *** search
- package java.security;
-
- import java.io.ByteArrayOutputStream;
- import java.util.Arrays;
- import javax.crypto.BadPaddingException;
- import javax.crypto.Cipher;
- import javax.crypto.IllegalBlockSizeException;
-
- class Signature$CipherAdapter extends SignatureSpi {
- private final Cipher cipher;
- private ByteArrayOutputStream data;
-
- Signature$CipherAdapter(Cipher var1) {
- this.cipher = var1;
- }
-
- protected void engineInitVerify(PublicKey var1) throws InvalidKeyException {
- this.cipher.init(2, var1);
- if (this.data == null) {
- this.data = new ByteArrayOutputStream(128);
- } else {
- this.data.reset();
- }
-
- }
-
- protected void engineInitSign(PrivateKey var1) throws InvalidKeyException {
- this.cipher.init(1, var1);
- this.data = null;
- }
-
- protected void engineInitSign(PrivateKey var1, SecureRandom var2) throws InvalidKeyException {
- this.cipher.init(1, var1, var2);
- this.data = null;
- }
-
- protected void engineUpdate(byte var1) throws SignatureException {
- this.engineUpdate(new byte[]{var1}, 0, 1);
- }
-
- protected void engineUpdate(byte[] var1, int var2, int var3) throws SignatureException {
- if (this.data != null) {
- this.data.write(var1, var2, var3);
- } else {
- byte[] var4 = this.cipher.update(var1, var2, var3);
- if (var4 != null && var4.length != 0) {
- throw new SignatureException("Cipher unexpectedly returned data");
- }
- }
- }
-
- protected byte[] engineSign() throws SignatureException {
- try {
- return this.cipher.doFinal();
- } catch (IllegalBlockSizeException var2) {
- throw new SignatureException("doFinal() failed", var2);
- } catch (BadPaddingException var3) {
- throw new SignatureException("doFinal() failed", var3);
- }
- }
-
- protected boolean engineVerify(byte[] var1) throws SignatureException {
- try {
- byte[] var2 = this.cipher.doFinal(var1);
- byte[] var3 = this.data.toByteArray();
- this.data.reset();
- return Arrays.equals(var2, var3);
- } catch (BadPaddingException var4) {
- return false;
- } catch (IllegalBlockSizeException var5) {
- throw new SignatureException("doFinal() failed", var5);
- }
- }
-
- protected void engineSetParameter(String var1, Object var2) throws InvalidParameterException {
- throw new InvalidParameterException("Parameters not supported");
- }
-
- protected Object engineGetParameter(String var1) throws InvalidParameterException {
- throw new InvalidParameterException("Parameters not supported");
- }
- }
-